home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir36 / feed10a.zip / FEED.PAS < prev    next >
Pascal/Delphi Source File  |  1994-06-14  |  2KB  |  94 lines

  1. {$M $4000,0,0}
  2. Program Feed;
  3.  
  4. {**********************************************************************
  5. FEED.PAS
  6.  
  7. Syntax: FEED [data file] to [Batch file]
  8.  
  9. by: Jim Scarletta,  (c) 1994
  10.  
  11. Written in Turbo Pascal V5.0
  12.  
  13. ***********************************************************************}
  14.  
  15.  
  16. Uses DOS;
  17.  
  18. var command,feedfile:comstr;
  19.     feedstr:string;
  20.     fin:text;
  21.     Path:PathStr; Dir:DirStr; Name:NameStr; Ext:ExtStr;
  22.     PathSave,DriveSave:string;
  23.  
  24. function Uppercase(s:string):string;
  25.   var ns:string; i:integer;
  26.   begin
  27.     ns:=s;
  28.     for i:=1 to length(s) do ns[i]:=upcase(s[i]);
  29.     UpperCase:=ns
  30.   end;
  31.  
  32. procedure CheckParams;
  33.   begin
  34.     if (paramcount <> 3) or (uppercase(paramstr(2)) <> 'TO') then begin
  35.       Writeln('Batch file parameter feeder. V1.0a Written by: Jim Scarletta');
  36.       writeln;
  37.       writeln('Syntax: FEED <filename> TO <batch file>');
  38.       halt(1)
  39.       end;
  40.     Command:=Fexpand(Paramstr(3));
  41.     fsplit(command,Dir,Name,Ext);
  42.     if Ext='' then begin
  43.       Writeln('Warning: FEED must feed to a batch file, assuming .BAT');
  44.       command:=command+'.BAT';
  45.       end;
  46.     fsplit(command,Dir,Name,Ext);
  47.     if Ext<>'.BAT' then begin
  48.       Writeln('Error: FEED must feed to a fully path qualified batch file');
  49.       halt(1);
  50.       end;
  51.     feedfile:=fexpand(paramstr(1));
  52.     {$I-}
  53.     assign(fin,feedfile);
  54.     reset(fin);
  55.     if ioresult <> 0 then begin
  56.       writeln('Unable to open FEED file');
  57.       halt(1);
  58.       end
  59.     {$I+}
  60.   end;
  61.  
  62.  
  63. Procedure SaveDir;
  64.   begin
  65.     Path:='.';
  66.     path:=fexpand(path);
  67.     fsplit(path,Dir,name,ext);
  68.     PathSave:=copy(path,3,length(path)-2);
  69.     DriveSave:=copy(path,1,2);
  70.   end;
  71.  
  72. procedure RestoreDir;
  73.   begin
  74.     exec(GETENV('COMSPEC'),' /c ' + DriveSave);
  75.     exec(GETENV('COMSPEC'),' /c cd' + PathSave);
  76.   end;
  77.  
  78.  
  79. begin
  80.   CheckParams;
  81.   SaveDir;
  82.   while not(EOF(fin)) do begin
  83.     readln(fin,feedstr);
  84.     writeln('Feeding: ',feedstr,' to ',command);
  85.     swapvectors;
  86.     exec(GETENV('COMSPEC'),' /c CALL '+ command + ' ' + feedstr);
  87.     if Doserror<>0 then writeln('DOS Error:',DOSError);
  88.     swapvectors;
  89.     end;
  90.   RestoreDir
  91. end.
  92.  
  93.  
  94.